---
title: "未归档的linux笔记"
date: 2019-3-26
categories:
- linux
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org6d30351">Get shell dir</a></li>
<li><a href="#orgb485d95">awk</a>
<ul>
<li><a href="#org10bf077">sort by length</a></li>
</ul>
</li>
<li><a href="#orgcd88def">find</a>
<ul>
<li><a href="#org124327a">stop after first match</a></li>
</ul>
</li>
<li><a href="#org6acd7c0">rsync 命令</a></li>
<li><a href="#orge585606">cp</a>
<ul>
<li><a href="#orga708484">cp -l</a></li>
</ul>
</li>
<li><a href="#orgd6d3abe">mktemp</a></li>
<li><a href="#org3d2d71a">fuser</a></li>
<li><a href="#org8584bcb">FAQ</a>
<ul>
<li><a href="#org92b98b3">ls 只显示目录</a></li>
<li><a href="#org242eb81">进制转换</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="outline-2" id="outline-container-org6d30351">
<h2 id="org6d30351">Get shell dir</h2>
<div class="outline-text-2" id="text-org6d30351">
<blockquote>
<p>
<a href="https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself">https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself</a>
</p>
</blockquote>
<div class="org-src-container">
<pre class="src src-sh"><span style="font-weight: bold; font-style: italic;">DIR</span>=<span style="font-style: italic;">"$( cd "$( dirname "${BASH_SOURCE[0]}" )" &gt;/dev/null 2&gt;&amp;1 &amp;&amp; pwd )"</span>
</pre>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-orgb485d95">
<h2 id="orgb485d95">awk</h2>
<div class="outline-text-2" id="text-orgb485d95">
</div>
<div class="outline-3" id="outline-container-org10bf077">
<h3 id="org10bf077">sort by length</h3>
<div class="outline-text-3" id="text-org10bf077">
<p>
awk '{ print length(), $0 | "sort -n" }' /path/to/text/file
</p>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-orgcd88def">
<h2 id="orgcd88def">find</h2>
<div class="outline-text-2" id="text-orgcd88def">
</div>
<div class="outline-3" id="outline-container-org124327a">
<h3 id="org124327a">stop after first match</h3>
<div class="outline-text-3" id="text-org124327a">
<p>
Using -quit
</p>
<p>
find . … -print -quit
</p>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-org6acd7c0">
<h2 id="org6acd7c0">rsync 命令</h2>
</div>
<div class="outline-2" id="outline-container-orge585606">
<h2 id="orge585606">cp</h2>
<div class="outline-text-2" id="text-orge585606">
</div>
<div class="outline-3" id="outline-container-orga708484">
<h3 id="orga708484">cp -l</h3>
<div class="outline-text-3" id="text-orga708484">
<p>
创建硬链接，而不是复制。如果 src &amp; dst 在不同的磁盘上，是否生效有待测试。
</p>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-orgd6d3abe">
<h2 id="orgd6d3abe">mktemp</h2>
<div class="outline-text-2" id="text-orgd6d3abe">
<p>
创建临时目录或文件
</p>
</div>
</div>
<div class="outline-2" id="outline-container-org3d2d71a">
<h2 id="org3d2d71a">fuser</h2>
<div class="outline-text-2" id="text-org3d2d71a">
<p>
查找文件被哪个进程使用，如果进程不是当前用户创建的，需要管理员权限才能显示
</p>
</div>
</div>
<div class="outline-2" id="outline-container-org8584bcb">
<h2 id="org8584bcb">FAQ</h2>
<div class="outline-text-2" id="text-org8584bcb">
</div>
<div class="outline-3" id="outline-container-org92b98b3">
<h3 id="org92b98b3">ls 只显示目录</h3>
<div class="outline-text-3" id="text-org92b98b3">
<p>
ls -p 选项在目录后面追加 '/'，这样就能通过grep过滤了
</p>
<pre class="example">
ls -p | grep -v /
</pre>
</div>
</div>
<div class="outline-3" id="outline-container-org242eb81">
<h3 id="org242eb81">进制转换</h3>
<div class="outline-text-3" id="text-org242eb81">
<div class="org-src-container">
<pre class="src src-bash"><span style="font-weight: bold;">echo</span> <span style="font-style: italic;">"obase=16;10"</span>|bc
输出16进制的10的表示 =&gt; A
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2019-3-26</p>
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
